tcp半开连接扫描,扫描速度快
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;using System.Text;using System.Threading;using System.Windows.Forms;using Metro;using Metro.Scanning;namespace WindowsFormsApplication1{ class Program { static void Main(string[] args) { Console.WriteLine("请输入要扫描的Ip地址"); string ip = Console.ReadLine(); Console.WriteLine("请输入要扫描的端口起始地址,用\",\"号分隔"); string txt = Console.ReadLine(); if (txt == null) return; args = txt.Split(','); ushort beginPort = ushort.Parse(args[0]); ushort endPort = ushort.Parse(args[1]); int length = endPort - beginPort; ushort[] ports = new ushort[length]; for (ushort i = 0; i < length; i ) ports[i] = (ushort)(beginPort i); NetworkInterfaceList list = new NetworkInterfaceList(); foreach (NetworkInterface ls in list.Interfaces) { TcpSynScanner scanner = new TcpSynScanner(new IPEndPoint(ls.Address, 0)); scanner.PortReply = scanner_PortReply; try { scanner.StartScan(IPAddress.Parse(ip), ports); } catch (Exception ex) { MessageBox.Show(ex.Message); } break; } Console.ReadLine(); } static void scanner_PortReply(IPEndPoint remoteEndPoint, TcpPortState state) { string txt = string.Format("{0}:{1}=>{2}", remoteEndPoint.Address, remoteEndPoint.Port, state); Console.WriteLine(txt); } }}
评论